﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy3_5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        class CountDistance
        {
            private float distance;
            private static float totalDistance = 0;

            public float Distance
            {
                get => distance;
                set
                {
                    distance = value;
                    totalDistance += value;
                }
            }

            public static float TotalDistance => totalDistance;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (float.TryParse(textBox1.Text, out float current))
            {
                CountDistance cd = new CountDistance();
                cd.Distance = current;
                MessageBox.Show($"您的汽车已经行驶 {CountDistance.TotalDistance} 公里");
            }
        }
    }
}
